Skip to content

Add pydantic schemas settings#20

Open
kowshikdontu wants to merge 8 commits intoOpenTekHub:mainfrom
kowshikdontu:add-pydantic-schemas-settings
Open

Add pydantic schemas settings#20
kowshikdontu wants to merge 8 commits intoOpenTekHub:mainfrom
kowshikdontu:add-pydantic-schemas-settings

Conversation

@kowshikdontu
Copy link
Contributor

@kowshikdontu kowshikdontu commented Jul 26, 2025

issue #19

  • Added Pydantic Schemas
    Created app/schemas/otp.py and app/schemas/token.py to define strong request and response models for the OTP API. These schemas enforce input validation, make endpoint contracts clear, and improve the OpenAPI documentation.

  • Centralized Configuration with BaseSettings
    Introduced app/config.py using BaseSettings (from the pydantic-settings package, as required by Pydantic v2+). This consolidates all configuration, such as Twilio credentials and JWT secrets into a single, type-safe location.

  • Twilio Verify v2 Migration
    Updated Twilio API calls to use client.verify.v2.services(...) instead of the deprecated v1 version. This aligns with the latest Twilio library and resolves PyCharm deprecation warnings.

  • Improved API Documentation
    Added response_model and status_code to each endpoint, and provided concise docstrings. This enhances the autogenerated API docs and makes responses and behaviors more predictable for consumers.

  • Added init.py to All Folders
    Included empty init.py files in all subfolders (app/, app/routers/, app/schemas/, etc.) to ensure Python treats them as packages. This allows for absolute imports (e.g., from app.schemas.otp import OTPRequest) and resolves module import issues in editors and during deployment.

  • improved requirements.txt with versions
    frozen the requirements for clean installations of pydantic-settings and new twilio versions

image image

@Harish-2003
Copy link
Collaborator

requriments.txt?
and currently we are planning to integrate with the neon db and will look into it once we integrate it and look into the possibilities of merging the issue

@kowshikdontu
Copy link
Contributor Author

kowshikdontu commented Jul 26, 2025

@Harish-2003

ok , after integrating the db, anyhow all the db.py functions also require pydantic schemas in orm_mode for clean validation , i will add them and test the api routes and update the branch sir

if you could assign this schema validation issue to me , I would wait for the db integration too.

thank you for reviewing the pr

@kowshikdontu kowshikdontu force-pushed the add-pydantic-schemas-settings branch from d449e45 to 97d178a Compare July 27, 2025 09:36
@kowshikdontu kowshikdontu reopened this Jul 27, 2025
@kowshikdontu
Copy link
Contributor Author

I made the existing code more enhanced and industry standard sir @Harish-2003

key improvements:

  • created schemas folder with otp_schemas and user_schemas
  • added status_codes to routes
  • changed the query parameter to json body path parameters as phone number is PII and not advisable to use query parameters
  • used the get_db func that is idle in database.py as dependency injection in routes and passed it as parameters to functions, which is more standard practice
  • added empty init.py to folder for better modularity
  • added access token verification functions and get current user functions in jwt.py for future use

I used postman to verify the routes and created a Twilio service to test all function, screenshots below with a one line description will helps you to understand the testing.

  • checked /otp/register with random phone number
Screenshot 2025-07-27 135202
  • checked send-otp function after creating a Twilio service free trail
Screenshot 2025-07-27 141253
  • checked verify-otp function but with not registered phone number
Screenshot 2025-07-27 141445
  • registered the crct phone number and verified the otp, otp got verified successfully ( changed the mail as previous mail raised unique constraint violation )
Screenshot 2025-07-27 141657 Screenshot 2025-07-27 141805

ss of otps received
image

FastAPI server side log

Screenshot 2025-07-27 141953

used a local .db file for quick testing and the visualization of db table is
Screenshot 2025-07-27 142252

from api side it all clean and clear to merge this pull request sir, as it is SQL Alchemy if we just change the database url to neon db , it works the same ! could you please look into this.

@kowshikdontu
Copy link
Contributor Author

@Harish-2003

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants